#MAKE SURE THE PACKAGES BELOW ARE INSTALLED PRIOR TO LOADING THEM



#Load packages
library(jtools)
library(sandwich)
library(sjmisc)
library(gridExtra)
library(ggplot2)
library(car)
library(lmtest)
library(multiwayvcov)
library(plyr)
library(dplyr)
library(tidyr)
library(broom)
library(reshape2)
library(reshape)
library(plyr)
library(Rmisc) 



#SET YOUR OWN WORKING DIRECTORY 

setwd(" ")

#################################################################################
#REPLICATION OF MAIN RESULTS AND ROBUSTNESS CHECKS
#################################################################################

#FIGURE 1 

data_wvs = read.csv("WVSplot_Dataset.csv", header=TRUE)
#Converting individual WVS data to long format
data_wvs_long <- gather(data_wvs, variable, answer, neighbour_immigrant:jobs_agree, factor_key=TRUE)
data_wvs_long

means_ci <- summarySE(na.omit(data_wvs_long), measurevar="answer", groupvars=c("wave", "variable"))
means_ci

pd <- position_dodge(0.1) # move them .05 to the left and right

means_ci <- means_ci %>%
  mutate(variable = recode(variable, neighbour_immigrant = "Don't oppose to have an immigrant as a neighbor",
                           neighbour_language = "Don't oppose to have a foreign-language speaking neighbor",
                           neighbour_religion = "Don't oppose to have a neighbor of a different religion",
                           jobs_agree = "Agree that employers should prioritize local workers"
  )
  )

ggplot(means_ci, aes(x=wave, y=answer)) + 
  geom_errorbar(aes(ymin=answer-ci, ymax=answer+ci), width=.1) + geom_line(aes(linetype=variable)) +
  geom_point(aes(shape=variable)) + 
  scale_x_continuous(breaks=seq(1, 3, 1), labels=c("Wave 5", "Wave 6", "Wave 7")) +
  xlab("") + ylab("Share of respondents") + theme(legend.title= element_blank()) +
  theme(text = element_text(size = 11)) + theme_bw() + theme(legend.title = element_blank())


rm(list = ls())

#################################################################################
data=read.csv("ProfileDataset.csv", header=TRUE)

#PREPARING THE CONJOINT DATA

#naming the variables

citizenshipbinary <- c(data$citizenshipbinary)
neighborbinary <- c(data$neighborbinary)
workpermitbinary <- c(data$workpermitbinary)
neighborscale <- c(data$neighborscale2)
citizenshipscale <- c(data$citizenshipscale2)
workpermitscale <- c(data$workpermitscale2)
female <- c(data$female)
male <- c(data$male)
young <- c(data$young)
old <- c(data$old)
arab <- c(data$arab)
kurd <- c(data$kurd)
turcoman <- c(data$turcoman)
sunni <- c(data$sunni)
alawite <- c(data$alawite)
christian <- c(data$christian)
literate <- c(data$literate)
primaryschool <- c(data$primary)
middleschool <- c(data$middle)
highschool <- c(data$high)
university <- c(data$university)
turkishfriends <- c(data$turkishfriends)
noturkishfriends <- c(data$doesnothaveturkishfriends)
knowsturkish <- c(data$knowsturkish)
doesnotspeakturkish <- c(data$doesnotknowTurkish)
foughtwithasad <- c(data$foughtwithasad)
foughtwithfsa <- c(data$foughtwithfsa)
notinvolved <- c(data$wasnotinvolved)
tortured <- c(data$tortured)
nottortured <- c(data$not.tortured)
idnumbernew <- c(data$idnumbernew)
sunni <- vector(length = dim(data)[1])
for (i in 1:dim(data)[1]) {
  if (data$christian[i] == 0 && data$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data$province)
respondent_religion <- as.factor(data$respondent_religion)
respondent_party <- as.factor(data$respondent_party)
respondent_education<-c(data$respondent_education)
respondent_education2 <-c(data$respondent_education2)
respondent_age <- as.factor(data$respondent_age)
respondent_kurd_lang <- as.factor(data$respondent_kurd_lang)
respondent_arab_lang <- as.factor(data$respondent_arab_lang)
respondent_armenian_lang <- as.factor(data$respondent_armenian_lang)
respondent_greek_lang <- as.factor(data$respondent_greek_lang)


data$respondent_female <- factor(data$respondent_female,
                                 levels = c(0,1),
                                 labels = c("Male", "Female"))


#################################################################################
#FIGURE 2
data2 <- subset(data, select=c("profileid", "neighborscale", "workpermitscale", "citizenshipscale"))
long <- melt(data2, id.vars = c("profileid"))

hist<-ggplot(long, aes(x=value, fill = variable)) + 
  geom_histogram(binwidth = 0.5, colour = "black", position = "dodge",alpha=0.6) +
  scale_x_continuous(limits = c(0.5, 7.5), breaks = seq(1, 7, 1))+
  scale_y_continuous(limits = c(0, 8000), breaks = seq(0, 8000, 2000))+
  theme_bw()+ scale_fill_manual(values=c("grey1", "grey41", "grey71"), name="Would you like this profile to",
                                breaks=c("neighborscale", "workpermitscale", "citizenshipscale"),
                                labels=c("be your neighbor", "get a work permit", "become a citizen")) + xlab("Support level: 1=`definitely don't want', 7=`definitely want'") + ylab("Number of responses") + theme(text = element_text(size = 15))

hist2<-hist+ theme(text = element_text(size = 12))




#################################################################################
#FIGURE 3 + TABLE B.1. in the Appendix: MAIN RESULTS


reg1 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool + middleschool
           + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg1)


reg2 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg2)

reg3 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg3)

reg4 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg4)

reg5 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg5)

reg6 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg6)

##FIGURE 3
plot1 <- plot_summs(reg1, reg3, reg5, 
                    model.names = c("Neighbor","Work permit","Citizenship"),
                    robust = "HC3", cluster="idnumbernew", 
                    scale = TRUE, plot.distributions = FALSE,
                    legend.title="Support for", 
                    coefs=c("Arab"= "arab", "Kurd"= "kurd", "Knows Turkish"= "knowsturkish",
                            "Has Turkish friends"= "turkishfriends",
                            "University"= "university", "High school"= "highschool", 
                            "Middle school"= "middleschool", "Primary school"= "primaryschool",
                            "Fought with Asad"= "foughtwithasad", "Fought with FSA"= "foughtwithfsa","Tortured"= "tortured",
                            "Female"="female", "Young"= "young", "Old"= "old", 
                            "Alawite"= "alawite",
                            "Christian"= "christian"),
                    facet.cols=2, facet.title.size = 14,
                    groups = list("1. Ethnicity--reference category: Turkomans"= c("Arab", "Kurd"), "2. Language--reference category: does not know Turkish"=c("Knows Turkish"), "3. Local connections--reference category: no local friends"=c("Has Turkish friends"), "4. Education--reference category: < primary school" = c("University", "High school", "Middle school", "Primary school"),
                                  "5. Fighting in civil war--reference category: did not fight" = c("Fought with Asad", "Fought with FSA"), "6. Tortured in Syria--reference category: was not tortured" = c("Tortured"), "7. Gender--reference category: male"=c("Female"), "8. Age--reference category: middle aged"=c("Young", "Old"), "9. Religion--reference category: Sunni Muslim"=c("Alawite", "Christian")))


apatheme=theme_bw()+
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.border=element_blank(),
        axis.line=element_line(),
        text=element_text(family='serif'),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        legend.text = element_text(size = 12),legend.position="right",
        legend.title = element_text(size=12),
        legend.justification="left",
        legend.margin=margin(1,1,1,1),
        legend.box.margin=margin(0,0,0,0))

#fig3
grid.arrange(plot1+apatheme+ labs(x = "Estimate ", y = NULL))


#TABLE B.2. Main results with forced choice (binary DV)
reg1a_binary <- glm(neighborbinary ~ female
                    + young + old
                    +  arab + kurd + alawite + christian + primaryschool + middleschool
                    + highschool + university
                    + turkishfriends + knowsturkish
                    + foughtwithasad + foughtwithfsa + tortured,
                    family = "binomial")
summary(reg1a_binary)
#Extract Log-likelihood
logLik(reg1a_binary)

reg2a_binary <- glm(workpermitbinary ~ female
                    + young + old
                    +  arab + kurd + alawite + christian + primaryschool
                    + middleschool + highschool + university
                    + turkishfriends + knowsturkish
                    + foughtwithasad + foughtwithfsa + tortured, 
                    family = "binomial")
summary(reg2a_binary)
#Extract Log-likelihood
logLik(reg2a_binary)

reg3a_binary <- glm(citizenshipbinary ~ female
                    + young + old
                    +  arab + kurd + alawite + christian + primaryschool
                    + middleschool + highschool + university
                    + turkishfriends + knowsturkish
                    + foughtwithasad + foughtwithfsa + tortured,
                    family = "binomial")
summary(reg3a_binary)
#Extract Log-likelihood
logLik(reg3a_binary) 


plot1 <- plot_summs(reg1a_binary, reg2a_binary, reg3a_binary, 
                    model.names = c("Neighbor","Work permit","Citizenship"),
                    robust = "HC3", cluster="idnumbernew", 
                    scale = TRUE, plot.distributions = FALSE,
                    legend.title="Support for", 
                    coefs=c("Female"="female",
                            "Young"= "young", "Old"= "old",
                            "Arab"= "arab", "Kurd"= "kurd","Alawite"= "alawite",
                            "Christian"= "christian","Primary school"= "primaryschool",
                            "Middle school"= "middleschool","High school"= "highschool",
                            "University"= "university","Has Turkish friends"= "turkishfriends",
                            "Knows Turkish"= "knowsturkish","Fought with Asad"= "foughtwithasad",
                            "Fought with FSA"= "foughtwithfsa","Tortured"= "tortured"))

apatheme=theme_bw()+
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.border=element_blank(),
        axis.line=element_line(),
        text=element_text(family='Helvetica'),
        axis.text=element_text(size=12),
        axis.title=element_text(size=14),
        legend.text = element_text(size = 14),legend.position="right",
        legend.title = element_text(size=16),
        legend.justification="left",
        legend.margin=margin(1,1,1,1),
        legend.box.margin=margin(0,0,0,0))

#fig3
grid.arrange(plot1+apatheme+ labs(x = "Estimate ", y = NULL))


#################################################################################
#INTERACTION WITH ETHNICITY: FIGURE 4 + TABLE B.3. + FIGURE E.11

reg1 <- lm(neighborscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, turcoman==1), cluster = 'idnumbernew')
summary(reg1)

reg2 <- lm(neighborscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, arab==1), cluster = 'idnumbernew')
summary(reg2)

#Arabs-Turkomans
##neighbor###university
(0.04510 -0.23673 )/ sqrt((0.08769^2 + 0.09376^2))

#neighbor #turkish friends
(0.02313 -0.08980)/ sqrt((0.05590^2 + 0.05859^2))

##neighbor ##knowsturkish
(0.10445 -0.31385)/ sqrt((0.05585^2 + 0.05879^2))

reg3 <- lm(neighborscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, kurd==1), cluster = 'idnumbernew')
summary(reg3)

##Arab-Kurd neighbor###university
(0.04510 -0.22179)/ sqrt((0.08769^2 + 0.08691^2))

#neighbor #turkish friends
(0.02313 -0.22582)/ sqrt((0.05590^2+ 0.05591^2 ))

##neighbor ##knowsturkish
(0.10445 -0.29812)/ sqrt((0.05585^2 + 0.05593^2 ))



#Kurds-Turkomans
##neighbor###university
(0.22179 -0.23673 )/ sqrt((0.08691^2 + 0.09376^2))

#neighbor #turkish friends
(0.22582 -0.08980)/ sqrt((0.05591^2 + 0.05859^2))

##neighbor ##knowsturkish
(0.29812 -0.31385)/ sqrt((0.05593^2 + 0.05879^2))


reg4 <- lm(workpermitscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, turcoman==1), cluster = 'idnumbernew')
summary(reg4)

reg5 <- lm(workpermitscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, arab==1), cluster = 'idnumbernew')
summary(reg5)

reg6 <- lm(workpermitscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, kurd==1), cluster = 'idnumbernew')
summary(reg6)


#work permit ###university
(0.203284 -0.370882)/ sqrt((7.678279e-03 +  7.777764e-03))

#work permit ###turkish friends
(0.041706 -0.112011)/ sqrt((3.119913e-03 + 3.218397e-03))

#work permit ###knowsturkish
(0.143653 -0.238836)/ sqrt((3.114622e-03 + 3.220868e-03 ))


####citizenship

reg7 <- lm(citizenshipscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, turcoman==1), cluster = 'idnumbernew')
summary(reg7)

reg8 <- lm(citizenshipscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, arab==1), cluster = 'idnumbernew')
summary(reg8)


reg9 <- lm(citizenshipscale ~ female +
             young + old + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured
           , data = subset(data, kurd==1), cluster = 'idnumbernew')
summary(reg9)

#citizenship #university
(0.055278 - 0.27308)/ sqrt(7.275702e-03 + 7.259778e-03)

#citizenship #turkishfriends
(0.079423  -  0.07996)/ sqrt(2.956334e-03 +3.004057e-03)

#citizenship #knowsturkish
(0.005449 - 0.22400)/ sqrt(2.951321e-03 + 3.006364e-03)

#fig4
plot1<- plot_summs(reg1, reg2, reg3, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university","Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Neighbor")

plot1<-plot1+ ggtitle("Neighbor") + theme(legend.position="none", plot.title = element_text(hjust = 0.5))



plot2<- plot_summs(reg4, reg5, reg6, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university", "Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Work permit")

plot2<-plot2+ggtitle("Work Permit") + theme(legend.position="none", axis.text.y = element_blank(), plot.title = element_text(hjust = 0.5))



plot3<- plot_summs(reg7, reg8, reg9, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university","Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Citizenship")

plot3<-plot3+ggtitle("Citizenship") + theme(legend.title=element_blank(), axis.text.y = element_blank(), plot.title = element_text(hjust = 0.5))


grid.arrange(plot1, plot2, plot3, ncol=3)

fig4 <- arrangeGrob(plot1, plot2, plot3, ncol=3) #generates fig4


##ROBUSTNESS: SPLIT SAMPLE---BINARY DV (FIGURE D.2.)

reg1 <- glm(citizenshipbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, turcoman==1))
summary(reg1)

reg2 <- glm(citizenshipbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, arab==1))
summary(reg2)

reg3 <- glm(citizenshipbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, kurd==1))
summary(reg3)

reg4 <- glm(workpermitbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, turcoman==1))
summary(reg4)

reg5 <- glm(workpermitbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, arab==1))
summary(reg5)

reg6 <- glm(workpermitbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, kurd==1))
summary(reg6)

reg7 <- glm(neighborbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, turcoman==1))
summary(reg7)

reg8 <- glm(neighborbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, arab==1))
summary(reg8)

reg9 <- glm(neighborbinary ~ female +
              young + old + alawite + christian 
            + primary + middle + high + university +
              turkishfriends + knowsturkish +
              + foughtwithasad + foughtwithfsa + tortured
            , data = subset(data, kurd==1))
summary(reg9)

plot3<- plot_summs(reg1, reg2, reg3, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university","Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Citizenship", groups=list(pane_1 = "Has Turkish friends",
                                                              pane_2 = "Knows Turkish"))

plot2<- plot_summs(reg4, reg5, reg6, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university", "Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Work permit",
                   groups=list(pane_1 = "Has Turkish friends", pane_2 = "Knows Turkish"))

plot1<- plot_summs(reg7, reg8, reg9, 
                   model.names = c("Turkoman","Arab", "Kurd"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University" = "university","Has Turkish friends"
                             = "turkishfriends", "Knows Turkish" = "knowsturkish"),
                   scale = TRUE
                   ,legend.title = "Neighbor",
                   groups=list(pane_1 = "Has Turkish friends", pane_2 = "Knows Turkish"))

#custom theme to format 
apatheme=theme_bw()+
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.border=element_blank(),
        axis.line=element_line(),
        text=element_text(family='Helvetica'),
        axis.text=element_text(size=10),
        axis.title=element_text(size=10),
        legend.text = element_text(size = 10),legend.position="right",
        legend.title = element_text(size=12),
        legend.justification="left",
        legend.margin=margin(1,1,1,1),
        legend.box.margin=margin(0,0,0,0))


grid.arrange(plot1+apatheme+ labs(x = "Estimate ", y = NULL),
             plot2+apatheme+ labs(x = "Estimate ", y = NULL),
             plot3+apatheme+ labs(x = "Estimate ", y = NULL),
             ncol=3)

#################################################################################
##INTERACTION WITH RESPONDENT PROFILE
##FIGURE F.12 -- interaction with respondent ethnicity


reg1 <- lm(neighborscale ~ female +
             young + old +  arab*respondent_kurd_lang + 
             arab*respondent_arab_lang + 
             kurd*respondent_kurd_lang +
             kurd*respondent_arab_lang +
             + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')

summary(reg1)

reg2 <- lm(workpermitscale ~ female +
             young + old +  arab*respondent_kurd_lang + 
             arab*respondent_arab_lang + 
             kurd*respondent_kurd_lang +
             kurd*respondent_arab_lang +
             + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')

summary(reg2)

reg3 <- lm(citizenshipscale ~ female +
             young + old +  arab*respondent_kurd_lang + 
             arab*respondent_arab_lang + 
             kurd*respondent_kurd_lang +
             kurd*respondent_arab_lang +
             + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')

summary(reg3)

stargazer(reg1, reg2, reg3,
          title="Regression Results",
          align=TRUE,
          dep.var.labels = c("Neighbor", "Work permit", "Citizenship"),
          omit.stat = c("f"),
          no.space=TRUE)

plot <- plot_summs(reg1, reg2, reg3, 
                   model.names = c("Neighbor","Work permit", "Citizenship"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("Kurd"="kurd", "Arab"="arab", "Kurdish respondent"="respondent_kurd_lang",
                             "Arab respondent"="respondent_arab_lang", 
                             "Kurdish respondent X Kurdish profile" = "respondent_kurd_lang:kurd",
                             "Kurdish respondent X Arab profile" = "arab:respondent_kurd_lang",
                             "Arab respondent X Kurdish profile" = "respondent_arab_lang:kurd",
                             "Arab respondent X Arab profile" = "arab:respondent_arab_lang"),
                   scale = TRUE
                   ,legend.title = "Support for", legend.position="bottom")

plot

##FIGURE F.13
#interaction with respondent's partisanship 

data_factor<-data
data_factor$respondent_party <- factor(data_factor$respondent_party)
data_factor$respondent_party <- factor(data_factor$respondent_party, levels=c('1','2','3', '4', '5', '6', '7', '8'),
                                       labels=c('AKP','CHP','MHP', 'HDP', 'Iyi Parti', 'Other', "Didn't vote", 'NA'))


reg1 <- lm(neighborscale ~ female +
             young + old +  arab*respondent_party + kurd*respondent_party + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = data_factor, cluster = 'idnumbernew')
summary(reg1)

reg2 <- lm(workpermitscale ~ female +
             young + old +  arab*respondent_party + kurd*respondent_party + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = data_factor, cluster = 'idnumbernew')
summary(reg2)

reg3 <- lm(citizenshipscale ~ female +
             young + old +  arab*respondent_party + kurd*respondent_party + alawite + christian 
           + primary + middle + high + university +
             turkishfriends + knowsturkish +
             + foughtwithasad + foughtwithfsa + tortured,
           data = data_factor, cluster = 'idnumbernew')
summary(reg3)

plot <- plot_summs(reg1, reg2, reg3, 
                   model.names = c("Neighbor","Work permit", "Citizenship"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("Kurd X CHP"="respondent_partyCHP:kurd", 
                             "Kurd X MHP" = "respondent_partyMHP:kurd",
                             "Kurd X HDP" = "respondent_partyHDP:kurd",
                             "Kurd X Iyi Parti" = "respondent_partyIyi Parti:kurd",
                             "Arab X CHP"="arab:respondent_partyCHP", 
                             "Arab X MHP" = "arab:respondent_partyMHP",
                             "Arab X HDP" = "arab:respondent_partyHDP",
                             "Arab X Iyi Parti" = "arab:respondent_partyIyi Parti"),
                   scale = TRUE
                   ,legend.title = "Support for")

plot

#################################################################################
##ROBUSTNESS: INTERACTION TERM INSTEAD OF SPLIT SAMPLES (FIGURE E.11)

reg1 <- lm(neighborscale ~ female +
             young + old +
             alawite + christian +
             primary*arab + primary*kurd +
             middle*arab + middle*kurd +
             high*arab + high*kurd +
             university*arab + university*kurd +
             turkishfriends*arab + turkishfriends*kurd + 
             knowsturkish*arab + knowsturkish*kurd +
             foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')
summary(reg1)

reg2 <- lm(workpermitscale ~ female +
             young + old +
             alawite + christian +
             primary*arab + primary*kurd +
             middle*arab + middle*kurd +
             high*arab + high*kurd +
             university*arab + university*kurd +
             turkishfriends*arab + turkishfriends*kurd + 
             knowsturkish*arab + knowsturkish*kurd +
             foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')
summary(reg2)

reg3 <- lm(citizenshipscale ~ female +
             young + old +
             alawite + christian +
             primary*arab + primary*kurd +
             middle*arab + middle*kurd +
             high*arab + high*kurd +
             university*arab + university*kurd +
             turkishfriends*arab + turkishfriends*kurd + 
             knowsturkish*arab + knowsturkish*kurd +
             foughtwithasad + foughtwithfsa + tortured,
           data = subset(data), cluster = 'idnumbernew')
summary(reg3)

#fig e.11.
plot <- plot_summs(reg1, reg2, reg3, 
                   model.names = c("Neighbor","Work permit", "Citizenship"),
                   robust=TRUE, cluster="idnumbernew",
                   coefs = c("University X Arab" = "arab:university",
                             "University X Kurd" = "kurd:university",
                             "Turkish friends X Arab" = "arab:turkishfriends",
                             "Turkish friends X Kurd" = "kurd:turkishfriends",
                             "Knows Turkish X Arab" = "arab:knowsturkish",
                             "Knows Turkish X Kurd" = "kurd:knowsturkish"),
                   scale = TRUE,
                   legend.title = "Support for", legend.position="bottom")

plot

#################################################################################
#FIGURE 5

different_values <- data.frame(female = c(1,1,0,0,0,1,0,0,0), young=c(1,1,1,1,1,1,1,1,1),
                               old=c(0,0,0,0,0,0,0,0,0), arab=c(1,0,0,1,0,0,1,1,0),
                               kurd=c(0,0,1,0,0,0,0,0,0), alawite=c(0,0,0,0,0,0,0,0,0),
                               christian=c(0,0,0,0,0,0,0,0,0), primaryschool=c(0,1,1,0,0,1,0,0,0),
                               middleschool=c(0,0,0,1,1,0,1,0,0), highschool=c(0,0,0,0,0,0,0,0,0),
                               university=c(1,0,0,0,0,0,0,1,1), turkishfriends=c(1,0,0,0,0,1,1,1,1),
                               knowsturkish=c(1,0,1,1,0,1,1,1,1), foughtwithasad=c(0,0,0,0,0,0,0,0,0),
                               foughtwithfsa=c(0,0,0,1,1,0,0,0,0), tortured=c(0,0,0,0,0,0,0,0,0))

reg1c <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool + middleschool
           + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg1c)
p1<-predict(reg1c, newdata = different_values, interval = 'confidence')

reg3c <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg3c)
p2<-predict(reg3c, newdata = different_values, interval = 'confidence')

reg6c <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg6c)
p3<-predict(reg6c, newdata = different_values, interval = 'confidence')


profiles <- rbind(p1,p2,p3)
profiles<-data.frame(profiles)

profiles$dv <- c(1,1,1,1,1,1,1,1,1,
                 2,2,2,2,2,2,2,2,2,
                 3,3,3,3,3,3,3,3,3)

profiles$dv2 <- c("neighbor","neighbor","neighbor","neighbor","neighbor","neighbor","neighbor","neighbor","neighbor",
                  "workpermit","workpermit","workpermit","workpermit","workpermit","workpermit","workpermit","workpermit","workpermit",
                  "citizenship","citizenship","citizenship","citizenship","citizenship","citizenship","citizenship","citizenship","citizenship")
profiles$profile <-c(1,2,3,4,5,6,7,8,9,
                     1,2,3,4,5,6,7,8,9,
                     1,2,3,4,5,6,7,8,9)

number_ticks <- function(n) {function(limits) pretty(limits, n)}


ggplot(profiles, aes(x = profile, y = fit, fill=dv2)) +
  geom_bar(stat = "identity", position = "dodge") + 
  geom_errorbar(aes(ymin = lwr, ymax = upr), width = 0.2, position = position_dodge(0.9)) +
  scale_x_continuous(breaks=number_ticks(9)) + 
  xlab("Profile") + ylab("Predicted probability of acceptance") + 
  labs(fill=NULL) +
  scale_fill_grey() +
  theme_bw() +
  theme(text = element_text(size = 16))   



#################################################################################
#################################################################################
##ROBUSTNESS CHECK: MAIN RESULTS SEPARATELY FOR SLOW AND FAST RESPONDENTS
##TABLE G.1. IN THE APPENDIX
rm(list = ls())
data = read.csv("ProfileDataset_slow.csv", header = TRUE)

#naming the variables
citizenshipbinary <- c(data$citizenshipbinary)
neighborbinary <- c(data$neighborbinary)
workpermitbinary <- c(data$workpermitbinary)
neighborscale <- c(data$neighborscale2)
citizenshipscale <- c(data$citizenshipscale2)
workpermitscale <- c(data$workpermitscale2)
female <- c(data$female)
male <- c(data$male)
young <- c(data$young)
old <- c(data$old)
arab <- c(data$arab)
kurd <- c(data$kurd)
turcoman <- c(data$turcoman)
sunni <- c(data$sunni)
alawite <- c(data$alawite)
christian <- c(data$christian)
literate <- c(data$literate)
primaryschool <- c(data$primary)
middleschool <- c(data$middle)
highschool <- c(data$high)
university <- c(data$university)
turkishfriends <- c(data$turkishfriends)
noturkishfriends <- c(data$doesnothaveturkishfriends)
knowsturkish <- c(data$knowsturkish)
doesnotspeakturkish <- c(data$doesnotknowTurkish)
foughtwithasad <- c(data$foughtwithasad)
foughtwithfsa <- c(data$foughtwithfsa)
notinvolved <- c(data$wasnotinvolved)
tortured <- c(data$tortured)
nottortured <- c(data$not.tortured)
idnumbernew <- c(data$idnumbernew)
sunni <- vector(length = dim(data)[1])
for (i in 1:dim(data)[1]) {
  if (data$christian[i] == 0 && data$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data$province)
respondent_religion <- as.factor(data$respondent_religion)
respondent_party <- as.factor(data$respondent_party)
respondent_education<-c(data$respondent_education)
respondent_education2 <-c(data$respondent_education2)
respondent_age <- as.factor(data$respondent_age)

data$respondent_female <- factor(data$respondent_female,
                                 levels = c(0,1),
                                 labels = c("Male", "Female"))

reg1slow <- lm(neighborscale ~ female
               + young + old
               +  arab + kurd + alawite + christian + primaryschool
               + middleschool + highschool + university
               + turkishfriends + knowsturkish
               + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg1slow)

reg2slow <- lm(workpermitscale ~ female
               + young + old
               +  arab + kurd + alawite + christian + primaryschool
               + middleschool + highschool + university
               + turkishfriends + knowsturkish
               + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg2slow)

reg3slow <- lm(citizenshipscale ~ female
               + young + old
               +  arab + kurd + alawite + christian + primaryschool
               + middleschool + highschool + university
               + turkishfriends + knowsturkish
               + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg3slow)
rm(data)

data = read.csv("ProfileDataset_fast.csv", header = TRUE)

#naming the variables
citizenshipbinary <- c(data$citizenshipbinary)
neighborbinary <- c(data$neighborbinary)
workpermitbinary <- c(data$workpermitbinary)
neighborscale <- c(data$neighborscale2)
citizenshipscale <- c(data$citizenshipscale2)
workpermitscale <- c(data$workpermitscale2)
female <- c(data$female)
male <- c(data$male)
young <- c(data$young)
old <- c(data$old)
arab <- c(data$arab)
kurd <- c(data$kurd)
turcoman <- c(data$turcoman)
sunni <- c(data$sunni)
alawite <- c(data$alawite)
christian <- c(data$christian)
literate <- c(data$literate)
primaryschool <- c(data$primary)
middleschool <- c(data$middle)
highschool <- c(data$high)
university <- c(data$university)
turkishfriends <- c(data$turkishfriends)
noturkishfriends <- c(data$doesnothaveturkishfriends)
knowsturkish <- c(data$knowsturkish)
doesnotspeakturkish <- c(data$doesnotknowTurkish)
foughtwithasad <- c(data$foughtwithasad)
foughtwithfsa <- c(data$foughtwithfsa)
notinvolved <- c(data$wasnotinvolved)
tortured <- c(data$tortured)
nottortured <- c(data$not.tortured)
idnumbernew <- c(data$idnumbernew)
qil <- c(data$QIL)
sunni <- vector(length = dim(data)[1])
for (i in 1:dim(data)[1]) {
  if (data$christian[i] == 0 && data$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data$province)
respondent_religion <- as.factor(data$respondent_religion)
respondent_party <- as.factor(data$respondent_party)
respondent_education<-c(data$respondent_education)
respondent_education2 <-c(data$respondent_education2)
respondent_age <- as.factor(data$respondent_age)

data$respondent_female <- factor(data$respondent_female,
                                 levels = c(0,1),
                                 labels = c("Male", "Female"))


reg1fast <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured+ factor(provinces), cluster = 'idnumbernew')
summary(reg1fast)

reg2fast <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg2fast)

reg3fast <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg3fast)


#################################################################################
##ROBUSTNESS CHECK: MAIN RESULTS WITH ONLY THE FIRST PAIR OF PROFILES
##TABLE G.2. IN THE APPENDIX
rm(list = ls())

data_logical = read.csv("ProfileDataset_task1.csv", header = TRUE)

#naming the variables
citizenshipbinary <- c(data_logical$citizenshipbinary)
neighborbinary <- c(data_logical$neighborbinary)
workpermitbinary <- c(data_logical$workpermitbinary)
neighborscale <- c(data_logical$neighborscale2)
citizenshipscale <- c(data_logical$citizenshipscale2)
workpermitscale <- c(data_logical$workpermitscale2)
female <- c(data_logical$female)
male <- c(data_logical$male)
young <- c(data_logical$young)
old <- c(data_logical$old)
arab <- c(data_logical$arab)
kurd <- c(data_logical$kurd)
turcoman <- c(data_logical$turcoman)
sunni <- c(data_logical$sunni)
alawite <- c(data_logical$alawite)
christian <- c(data_logical$christian)
literate <- c(data_logical$literate)
primaryschool <- c(data_logical$primary)
middleschool <- c(data_logical$middle)
highschool <- c(data_logical$high)
university <- c(data_logical$university)
turkishfriends <- c(data_logical$turkishfriends)
noturkishfriends <- c(data_logical$doesnothaveturkishfriends)
knowsturkish <- c(data_logical$knowsturkish)
doesnotspeakturkish <- c(data_logical$doesnotknowTurkish)
foughtwithasad <- c(data_logical$foughtwithasad)
foughtwithfsa <- c(data_logical$foughtwithfsa)
notinvolved <- c(data_logical$wasnotinvolved)
tortured <- c(data_logical$tortured)
nottortured <- c(data_logical$not.tortured)
idnumbernew <- c(data_logical$idnumbernew)
sunni <- vector(length = dim(data_logical)[1])
for (i in 1:dim(data_logical)[1]) {
  if (data_logical$christian[i] == 0 && data_logical$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data_logical$province)
respondent_religion <- as.factor(data_logical$respondent_religion)
respondent_party <- as.factor(data_logical$respondent_party)
respondent_education<-c(data_logical$respondent_education)
respondent_education2 <-c(data_logical$respondent_education2)
respondent_age <- as.factor(data_logical$respondent_age)

data_logical$respondent_female <- factor(data_logical$respondent_female,
                                         levels = c(0,1),
                                         labels = c("Male", "Female"))



reg2 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg2)

reg4 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg4)

reg6 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg6)


#################################################################################
##ROBUSTNESS CHECK: OMITTING ILLOGICAL RESPONSES--INCONSISTENCY BETWEEN LIKERT AND FORCED CHOICE
##TABLE G.3. IN THE APPENDIX
rm(list = ls())

data_logical = read.csv("ProfileDataset_alllogical.csv", header = TRUE)

#naming the variables
citizenshipbinary <- c(data_logical$citizenshipbinary)
neighborbinary <- c(data_logical$neighborbinary)
workpermitbinary <- c(data_logical$workpermitbinary)
neighborscale <- c(data_logical$neighborscale2)
citizenshipscale <- c(data_logical$citizenshipscale2)
workpermitscale <- c(data_logical$workpermitscale2)
female <- c(data_logical$female)
male <- c(data_logical$male)
young <- c(data_logical$young)
old <- c(data_logical$old)
arab <- c(data_logical$arab)
kurd <- c(data_logical$kurd)
turcoman <- c(data_logical$turcoman)
sunni <- c(data_logical$sunni)
alawite <- c(data_logical$alawite)
christian <- c(data_logical$christian)
literate <- c(data_logical$literate)
primaryschool <- c(data_logical$primary)
middleschool <- c(data_logical$middle)
highschool <- c(data_logical$high)
university <- c(data_logical$university)
turkishfriends <- c(data_logical$turkishfriends)
noturkishfriends <- c(data_logical$doesnothaveturkishfriends)
knowsturkish <- c(data_logical$knowsturkish)
doesnotspeakturkish <- c(data_logical$doesnotknowTurkish)
foughtwithasad <- c(data_logical$foughtwithasad)
foughtwithfsa <- c(data_logical$foughtwithfsa)
notinvolved <- c(data_logical$wasnotinvolved)
tortured <- c(data_logical$tortured)
nottortured <- c(data_logical$not.tortured)
idnumbernew <- c(data_logical$idnumbernew)
sunni <- vector(length = dim(data_logical)[1])
for (i in 1:dim(data_logical)[1]) {
  if (data_logical$christian[i] == 0 && data_logical$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data_logical$province)
respondent_religion <- as.factor(data_logical$respondent_religion)
respondent_party <- as.factor(data_logical$respondent_party)
respondent_education<-c(data_logical$respondent_education)
respondent_education2 <-c(data_logical$respondent_education2)
respondent_age <- as.factor(data_logical$respondent_age)

data_logical$respondent_female <- factor(data_logical$respondent_female,
                                 levels = c(0,1),
                                 labels = c("Male", "Female"))


reg1 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool + middleschool
           + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg1)

reg2 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg2)

reg3 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg3)

reg4 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg4)

reg5 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured, cluster = 'idnumbernew')
summary(reg5)

reg6 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew')
summary(reg6)

###############################################################################
#WEIGHTS--TABLE B.4
###############################################################################

rm(list = ls())

data_weights = read.csv("ProfileDataset_weights.csv", header = TRUE)

#naming the variables
citizenshipbinary <- c(data_weights$citizenshipbinary)
neighborbinary <- c(data_weights$neighborbinary)
workpermitbinary <- c(data_weights$workpermitbinary)
neighborscale <- c(data_weights$neighborscale2)
citizenshipscale <- c(data_weights$citizenshipscale2)
workpermitscale <- c(data_weights$workpermitscale2)
female <- c(data_weights$female)
male <- c(data_weights$male)
young <- c(data_weights$young)
old <- c(data_weights$old)
arab <- c(data_weights$arab)
kurd <- c(data_weights$kurd)
turcoman <- c(data_weights$turcoman)
sunni <- c(data_weights$sunni)
alawite <- c(data_weights$alawite)
christian <- c(data_weights$christian)
literate <- c(data_weights$literate)
primaryschool <- c(data_weights$primary)
middleschool <- c(data_weights$middle)
highschool <- c(data_weights$high)
university <- c(data_weights$university)
turkishfriends <- c(data_weights$turkishfriends)
noturkishfriends <- c(data_weights$doesnothaveturkishfriends)
knowsturkish <- c(data_weights$knowsturkish)
doesnotspeakturkish <- c(data_weights$doesnotknowTurkish)
foughtwithasad <- c(data_weights$foughtwithasad)
foughtwithfsa <- c(data_weights$foughtwithfsa)
notinvolved <- c(data_weights$wasnotinvolved)
tortured <- c(data_weights$tortured)
nottortured <- c(data_weights$not.tortured)
idnumbernew <- c(data_weights$idnumbernew)
sunni <- vector(length = dim(data_weights)[1])
for (i in 1:dim(data_weights)[1]) {
  if (data_weights$christian[i] == 0 && data_weights$alawite[i] == 0)
    sunni[i] <- 1
}
provinces <- as.factor(data_weights$province)
respondent_religion <- as.factor(data_weights$respondent_religion)
respondent_party <- as.factor(data_weights$respondent_party)
respondent_education<-c(data_weights$respondent_education)
respondent_education2 <-c(data_weights$respondent_education2)
respondent_age <- as.factor(data_weights$respondent_age)

data_weights$respondent_female <- factor(data_weights$respondent_female,
                                         levels = c(0,1),
                                         labels = c("Male", "Female"))
weights <-c(data_weights$weights)

reg1 <- lm(neighborscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool + middleschool
           + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), cluster = 'idnumbernew', weights=weights)
summary(reg1)

reg2 <- glm(neighborbinary ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), family = "binomial", weights=weights)
summary(reg2)

reg3 <- lm(workpermitscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured+ factor(provinces), cluster = 'idnumbernew', weights=weights)
summary(reg3)

reg4 <- glm(workpermitbinary ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), family = "binomial", weights=weights)
summary(reg4)

reg5 <- lm(citizenshipscale ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured+ factor(provinces), cluster = 'idnumbernew', weights=weights)
summary(reg5)

reg6 <- glm(citizenshipbinary ~ female
           + young + old
           +  arab + kurd + alawite + christian + primaryschool
           + middleschool + highschool + university
           + turkishfriends + knowsturkish
           + foughtwithasad + foughtwithfsa + tortured + factor(provinces), family = "binomial", weights=weights)
summary(reg6)

